<!--************************************************************************************************-->
<!-- < groupPage.php >                                                                               -->
<!-- Copyright (c) 2012-2013 San Yat-sun University School of Software                              -->
<!-- Founder: Xiaofen Huang                                                                          -->
<!-- Stu : 10389169                                                                                 -->
<!-- Modifier: Xiaoxin Mo                                                                           -->
<!-- Stu : 10389159                                                                                 -->
<!-- Date: 2012-01-01                                                                               -->
<!-- Destription : 搜索结果，暂时只能通过全名来得到结果          -->
<!--                                                                                        -->
<!-- Version : 2.1                                                                                  -->
<!-- LastUpdate : 2012-01-01 14:00 BY XiaoxinMo														-->
<!-- description: show the value of the group                                                    -->
<!--************************************************************************************************-->

<!DOCTYPE html>
<?php
	include_once("header.php");
	//include_once("bottom.php");
	include_once("../manager/GroupManager.php");
	include_once("../manager/NoteManager.php");
	
	
	$group_name = $_REQUEST['group_name'];
	$_SESSION['currentGroup'] = $group_name;
	$group_value = GroupManager::getInstance()->getValueByGroupname($group_name);
	//echo count($group_value["ID"]);
	$group_member_list = GroupManager::getInstance()->getMemberListByGroupName($group_name);
	$group_note_book_list = array();
	$group_note_noter_list = array();
	$group_note_content_list = array();
	
	$is_manager = false;
	if (isset($_SESSION['currentUser']))
		if ($_SESSION['currentUser'] === $group_value['ManagerName'])
			$is_manager = true;
			
	$is_member = false;
	foreach($group_member_list as $member)
	{
		if (isset($_SESSION['currentUser']))
			if ($_SESSION['currentUser'] === $member)
				$is_member = true;
		$sql = NoteManager::getInstance()->getValueByUsername($member);

		while ($row = mysql_fetch_array($sql))
		{
			$group_note_book_list[] = $row['Bookname'];
			$group_note_noter_list[] = $row['Username'];
		}
		
		$group_note_content_list = NoteManager::getInstance()->getNotelistByUsername($member, 30);
	}
	
	$group_comment_list = GroupManager::getInstance()->getCommentListByGroupName($group_name);
	
	//print_r($group_member_list);
	//print_r($group_note_list);
	//print_r($group_comment_list);
?>
<html lang="zh-hk">
<head>
	<title>Tiny bOOk</title>
	
	<meta http-equiv="Content-Type" content="text/html charset=UTF-8">
	<meta name="contentType" value="text/html  charset=GBK">
	<meta name="description" content="在这里你可以看到最新发布的书籍，和好友共享对某本书的评论和笔记">
	<meta http-equiv="imagetoolbar" content="no">
	<meta name="viewport" content="width=1036">
	
	<link rel="stylesheet" type="text/css" href="../css/groupPage.css">
</head>

<body>
	<div id="main">
		<!--**********************内容***********************************-->
		<div id="left">
			<div id="content">
				<div id="page_head">
					<img src="../images/Groups/<?=$group_name?>.jpg"/>
					<span class="translatable" lang="Groups"><?=$group_name?></span>
				</div>
				<div id="selected_cc" class="page_tabs">
				<ul>
					<li id="aa">
						<a href="">
						<span class="translatable" lang="My groups">首页</span>
						</a>
					</li>
				</ul>
				</div>
				<!--****************************************************-->
				<div id="group_profile">
					<table>
					<tbody>
					<tr>
					<td>
					<p>
						<?= $group_value['GroupBrief']?>
					</p>
					</td>
					</tr>
					</tbody>
					</table>
				</div>
				
				<?php
				if ($is_member)
				{
				?>
				<div id="group_topic">
					<h4 class="divider_head">
						<span class="translatable" lang="New topics">New notes</span>
					</h4>
					<table id="group_discuss">
						<tbody>
							<tr class="cir">
								<th class="discuss_title">
									<span class="translatable" lang="Title">笔记</span>
									<?php
									for($i = 0; $i < count($group_note_book_list); $i++)
									{
									?>
										<p><a href="bookPage.php?book_name=<?=$group_note_book_list[$i]?>"><?=$group_note_book_list[$i]?></a></p>
									<?php
									}
									?>	
								</th>
								<th class="notename">
									<span class="translatable" lang="Author">作者</span>
									<?php
									for($i = 0; $i < count($group_note_noter_list); $i++)
									{
									?>
										<p><a href="userPage.php?user_name=<?=$group_note_noter_list[$i]?>"><?=$group_note_noter_list[$i]?></a></p>
									<?php
									}
									?>	
								</th>
								<th class="notecontent">
									<span class="translatable" lang="Notecontent">内容</span>
									<?php
									for($i = 0; $i < count($group_note_content_list); $i++)
									{
									?>
										<p><?=$group_note_content_list[$i]?></p>
									<?php
									}
									?>	
								</th>
							</tr>
						</tbody>
					</table>
				</div>
				<?php
				}else{
				?>
					<p>你还不是我们的成员，无法查看笔记。快来加入我们小组吧！</p>
					<?php
					if (isset($_SESSION['currentUser']))
					{
					?>
						<form action="addGMResult.php" method="post">
							<div id="adduser">
								<label><input type="hidden" name="groupname" value="<?=$group_name?>" /></label>
								<label><input type="hidden" name="username" value="<?=$_SESSION['currentUser']?>" /></label>
								<input type="submit" value="加入小组">
							</div>
						</form>
					<?php
					}else{
					?>
						<form action="login.php">
							<div id="adduser">
								<input type="submit" value="登陆">
							</div>
						</form>
					<?php
					}
					?>
				<?php
				}
				?>
			</div>
		</div><!--end of left-->
		<div id="right">
			<div id="member">
				<span class="translatable" lang="Notecontent">小组成员>></span>
				<?php
				for($i = 0; $i < count($group_member_list); $i++)
				{
				?>
					<p><a href="userPage.php?user_name=<?=$group_member_list[$i]?>"><?=$group_member_list[$i]?></a></p>
				<?php
				}
				?>	
			</div>
			
			<?php
			if ($is_manager)
			{
			?>
				<!--输入一个用户名，摁“删除”,就直接将该用户删除掉-->
				<form action="deleteGMResult.php" method="post">
					<div id="deleteuser">
						<p>删除用户：</p>
						<input type="hidden" name="groupname" value="<?=$group_name?>">
						<input type="text" name="username">
						<input type="submit" value="删除">
					</div>
				</form>
				
				<!--输入一个用户名，摁“添加”，就直接在DB里面添加一个用户-->
				<form action="addGMResult.php" method="post">
					<div id="adduser">
						<p>添加用户：</p>
						<input type="hidden" name="groupname" value="<?=$group_name?>">
						<label class="username">用户名<input type="text" size="7" name="username"/></label>
						<input type="submit" value="添加">
					</div>
				</form>
			
			<?php
			}
			?>
		</div>
	</div><!--end of main-->
</body>